package com.snake.springboot.custom.controller.fileoss;

import com.snake.springboot.custom.api.model.common.KeyVal;
import com.snake.springboot.custom.api.model.fileoss.FileOSSModel;
import com.snake.springboot.custom.api.model.fileoss.OSSType;
import com.snake.springboot.custom.api.service.fileoss.FileOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>文件管理-文件OSS
 * 类{@code FileOss} </br>
 * 创建时间2025/5/7 14:57
 * @author yangxt
 * @see
 */
@Api(tags = "文件管理-文件OSS")
@RestController
@RequestMapping("/file-oss")
public class FileOssController {

    private FileOssService fileOssService;
    @Autowired
    public FileOssController(FileOssService fileOssService) {
        this.fileOssService = fileOssService;
    }

    @ApiOperation("OSS配置")
    @PostMapping("/oss-config")
    public ResponseResult<FileOSSModel> ossConfig(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) FileOSSModel model) {
        FileOSSModel result = fileOssService.ossConfig(model);
        return ResponseResultFactory.ucc("配置成功！", result);
    }


    @ApiOperation("OSS配置查询")
    @PostMapping("/oss-query")
    public ResponseResult<FileOSSModel> ossQuery(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody FileOSSModel model) {
        FileOSSModel result = fileOssService.ossQuery(model);
        return ResponseResultFactory.ucc("OSS配置查询成功！", result);
    }

    @ApiOperation("OSS配置删除")
    @PostMapping("/oss-delete")
    public ResponseResult<Object> ossDelete(@RequestBody FileOSSModel model){
        fileOssService.ossDelete(model);
        return ResponseResultFactory.ucc("删除成功！");
    }

    @ApiOperation("查询OSS类型")
    @PostMapping("/oss-type")
    public ResponseResult<List<KeyVal<String, String>>> ossType(){
        List<KeyVal<String, String>> list = OSSType.getEnumList();
        return ResponseResultFactory.ucc("OSS类型！",list);
    }


}
